from shpReader import *
from numpy import *

class VectorComputation:
    
    def __init__(self,vectCoord):
        self.vectCoord=vectCoord
        self.vectDirect={}
        self.vectDist={}
        
    def computeDirection(self):
        for k, v in self.vectCoord.items():
            deg = rad2deg(arctan2((v[3]-v[1]),(v[2]-v[0])))
            
            if -90<deg<0:
                deg=deg+360
                direct = 'SouthEast'
            elif -180<deg<-90:
                deg=deg+360
                direct = 'SouthWest'
            elif 90<deg<180:
                direct = 'NorthWest'
            elif 0<deg<90:
                direct = 'NorthEast'
            elif deg==0:
                direct = 'East'
            elif deg==90:
                direct = 'North'
            elif deg==180:
                direct = 'West'
            elif deg==-90:
                deg=deg+360
                direct = 'South'
            
            self.vectDirect[k]=[deg, direct]
            
    def computeDistance(self):
        for k, v in self.vectCoord.items():            
            dist_feet = sqrt(square(v[3]-v[1])+square(v[2]-v[0]))
            dist_mile = dist_feet/5280
            
            self.vectDist[k]=[dist_feet, dist_mile]
            
        